<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ JSON.stringify(text) == '{}' ? '添加作业' : '修改作业' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form :form="form">
				<a-form-item label="题目">
					<a-textarea v-decorator="['Title', { rules: [{ required: true, message: '请输入题目' }] }]" />
				</a-form-item>
					<a-form-item label="答题方式">
						<a-radio-group 
							v-decorator="['Type', { rules: [{ required: true, message: '请选择答题方式' }] }]"
							name="radioGroup">
							<a-radio v-for="(item, i) in TypeData" :key="i" :value="item.Key">
								{{ item.Value }}
							</a-radio>
						</a-radio-group>
					</a-form-item>

					
					
					
					<a-form-item class="fixed-bottom">

					<!-- 	<a-popconfirm title="暂存后不会提交,在列表页点击提交按钮提交!" ok-text="好的" cancel-text="取消"
							@confirm="handleSubmit" @cancel="cancel" v-if="JSON.stringify(text) == '{}'">
							<a-button type="primary">暂存</a-button>
						</a-popconfirm> -->
						<a-button type="primary"  @click="handleSubmit">
							{{JSON.stringify(text) == '{}'?'确认添加':'确认修改'}}
						</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-item>
				</a-form>
			</div>
		</div>
	</div>
</template>

<script>
	import moment from 'moment';
	import {
		UserActivityJobDoAdd,
		UserActivityJobDoUpdate
	} from '@/api/follow';
	export default {
		props: {
			text: Object,
			// ActivityTypeData: Array,
			// ActivityTypePrizeTypeList: Array,
			// ActivityMemberTypeList: Array
		},
		watch: {
			text: function(text) {
				let that = this;
				that.icofileList = []
				if (JSON.stringify(text) == '{}') {
					that.currentID = ''
					// setTimeout(function() {
					// 	that.form.setFieldsValue({
					// 		IsTeacherExam: false,
					// 		IsAgreeUpdate: false
					// 	});
					// },300)
				} else {
					that.currentID = text.ID;
					that.$nextTick(() => {
						that.form.setFieldsValue({
							Type: text.Type,
							Title:text.Title
						});
					})

				}

			}
		},
		data() {
			return {
				zdyApplyCustomScore: false,
				ActivityTypeApplyList2: [],
				defaultFileList: [],
				requestUrl: this.global.requestUrl,
				icofileList: [],
				fileList: {},
				replaceFields: {
					children: 'children',
					title: 'title',
					key: 'ID',
					value: 'ID'
				},
				treeselect: true,
				ActivityTypeApplyList: [],
				ActivityTypeApplyID: [],
				itemData: [],
				rules: {},
				Type: '1',
				TypeData: [{
						Key: '1',
						Value: "多行文本在线输入"
					},
					{
						Key: '2',
						Value: "上传附件"
					}
				],
				ActivityTypeData: [],
				ActivityMemberTypeList: [],
				ActivityTypePrizeTypeList: [],
				// ActivityTypePrizeTypeList:[],
				GetActivityTypePrizeListCommon: [],
				ActivityTypeScoreList: [],
				dataForm: [],
				loading: false,
				formLayout: 'horizontal',
				form: this.$form.createForm(this, {
					name: 'coordinated'
				}),
				currentID: '',
				UserList: [],
				OldActivityTypeApplyList: [],
				zhouqi: {
					ApplyEndTime: "",
					ApplyStartTime: ''

				},
				jibieDetail: {},
				leaveChange: [],
				ActivityTypePrizeTypeListweiqu: [],
				pubdata: [],
			};
		},
		created() {
			// this.getOtherListList();

			// setTimeout(function() {
			// 	this.getOtherList();
			// }, 300);
			// this.$nextTick(() => {
			// 	this.form.setFieldsValue({
			// 		Type: '1'
			// 	});
			// })

		},
		methods: {
			moment,
			closeFunction(data) {
				this.form.resetFields();
				this.$emit('closeFun', data);
			},
			handleSubmit(e) {
				this.form.validateFields(async (err, values) => {
					if (!err) {
						let data = {};
						data = values;
						data.ActivityID=this.$route.query.ID;
						data.ID=this.currentID;
						console.log(data.fileData);
						let res = {};
						if (!this.currentID) {
							res = await UserActivityJobDoAdd(data);
						} else {
							data.id = this.currentID;
							res = await UserActivityJobDoUpdate(data);
						}
						console.log(res);
						if (res.data.code === 0) {
							this.$message.success(res.data.msg);
							this.closeFunction('1');
						} else {
							this.$message.error(res.data.msg);
						}
					}
				});
			}
		}
	};
</script>

<style lang="less" scoped>
	/deep/.ant-form {
		margin-top: 50px;
		padding-bottom: 50px;
	}

	/deep/.ant-form-item {
		margin: 20px 50px;
		display: flex;
	}

	/deep/.ant-form-item-label {
		width: 100px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	/deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	/deep/.ant-calendar-picker {
		width: 100% !important;
	}

	.ant-upload-list-picture-card-container {
		width: 80px;
		height: 80px;
	}

	.zhouqiBen {
		font-size: 12px;
		padding-left: 60px;

	}

	.red {
		color: red;
	}

	.green {
		color: green;
	}
</style>
